package com.laicunba.ext.web.controller.h5.activity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.laicunba.ext.web.controller.BaseController;
import com.laicunba.pojo.RegistryDO;
import com.laicunba.service.RegistryService;
import com.laicunba.util.StringUtil;

@Controller
@RequestMapping(value = "/h5/ext/activity")
public class DownloadApp20170809Controller extends BaseController {
	
	@Autowired
	private RegistryService registryService;

	@RequestMapping(value = "/netease_download_0809.htm")
	public ModelAndView neteaseDownloadForm() {
		ModelAndView view = new ModelAndView("netease_download_0809.jsp");
		
		return view;
	}

	@RequestMapping(value = "/common_download_{chennelId}.htm")
	public ModelAndView downloadApp0717Form(@PathVariable("chennelId") String chennelId) {
		ModelAndView view = new ModelAndView("common_download_0809.jsp");
		if(StringUtil.isNotEmpty(chennelId) && "jm11,jm12,wt01,wjx01".contains(chennelId)) {
			view.addObject("chennelId", chennelId);
		}
		return view;
	}
	
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/netease_download_0809_save.htm")
	public String neteaseDownload0809(HttpServletRequest request, HttpServletResponse response, String mobile) {
		JSONObject json = new JSONObject();
		if (!StringUtil.isMobileNumber(mobile)) {
			json.put("status", 0);
		}
		if (registryService.get(RegistryDO.class, "act.0809." + mobile) == null && registryService.create("act.0809." + mobile, mobile)) {
			json.put("status", 1);
		} else {
			json.put("status", 2);
		}

		return json.toJSONString();
	}
	
}
